import { Button, Gap, SearchForm, Table, Upload } from "@/components";
import { useMyTable, useRowSelection } from "@/hooks";
import { getMyUrlParams } from "@/utils";
import { getManagementList } from "../management/service";
import { getColumns, getFields } from "./helper";
import { useNavigate, useParams } from "react-router-dom";
import { ColumnsType } from "antd/es/table";
import { Space, message } from "antd";
import { getAssetList, upload } from "./service";
import { TASK_KEY } from "@/constants";

const Assets = () => {
  const { taskKey } = useParams();
  const tableTitle = TASK_KEY.find(item => item.value === taskKey)?.label;
  const { search, refresh, options, ...restAttrs } = useMyTable({
    service: getAssetList,
    initParams: {
      tableName: taskKey
    },
  });

  const handleUpload = async (params: any) => {
    const { onSuccess, onError, file, onProgress } = params;
    const [err, res] = await upload({
      file,
      type: taskKey,
    });
    if (err) return message.error("上传失败!");
    message.success("上传成功!");
    refresh()
  };
  return (
    <>
      {/* <>
        <SearchForm fields={getFields()} query={search} labelWidth={105} />
        <Gap />
      </> */}
      <Table
        title={`${tableTitle}列表`}
        rowKey={"id"}
        // rowSelection={rowSelection}
        extra={<Upload customRequest={handleUpload} showUploadList={false} />}
        columns={getColumns(options)}
        {...restAttrs}
      />
    </>
  );
};
export default Assets;
